import { resolve } from 'node:path'
import type { PluginOption } from 'vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) {
    // 获取当前工作目录
    // const currentDir = process.cwd()
    // 计算相对路径
    // const relativeIconPath = resolve(currentDir, 'src/assets/icons').replace(currentDir, '').replace(/\\/g, '/').substring(1)

    const svgIconsPlugin = createSvgIconsPlugin({

        iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
        svgoOptions: isBuild
    })
    return svgIconsPlugin as PluginOption
}
